const fs = require('fs-extra')
const path = require('path')


async function copy(sourceDir,targetDir) {
    let reject, resolve
    new Promise((_resolve,_reject) => {
        reject = _reject
        resolve = _resolve
    })
    await fs.remove(targetDir)

    fs.copy(sourceDir, targetDir, {
        filter: (src) => {
            return !src.endsWith('.map');
        }
    }, (err) => {
        if (err) {
            return console.error('无法复制文件: ' + err);
        }
    });
}

(async  function() {
    await copy(path.join(__dirname, '../packages/www/.vitepress/dist'),path.join(__dirname, '../dist'))
    await copy(path.join(__dirname, '../packages/worker/dist/index.js'),path.join(__dirname, '../dist/_worker.js'))
    console.log("copy.cjs run success!")
})()


